﻿/*********************************************************************************************************************
VanguardDocumentation, Table EntityPropertyRules

© 2014 Erik Ackerholm

This file is part of SqlVanguard.

SqlVanguard is free software: you can redistribute it and/or modify it under the terms of the GNU General Public 
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later 
version.

SqlVanguard is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with SqlVanguard. If not, see 
<http://www.gnu.org/licenses/>.
*********************************************************************************************************************/

if
	not exists (
		select *
		from sys.schemas as s
			inner join sys.objects as o on (s.schema_id = o.schema_id)
		where s.name = 'VanguardDocumentation' and o.[type] = 'U'
			and o.name = 'EntityPropertyRules'
	)
begin
	
	create table VanguardDocumentation.EntityPropertyRules (
		RuleID                   integer not null               identity (1, 1),
		Level0Type               varchar(64),
		Level1Type               varchar(64),
		Level2Type               varchar(64),
		PropertyName             nvarchar(64) not null,
		Usage                    varchar(16) not null
			constraint DF_EntityPropertyRules_Usage default 'optional',
		MinSize                  integer not null
			constraint DF_EntityPropertyRules_MinSize default 0,
		MaxSize                  integer not null
			constraint DF_EntityPropertyRules_MaxSize default 2147483647,
		
		constraint PK_EntityPropertyRules
			primary key clustered (RuleID),
		constraint UQ_EntityPropertyRules_CombinedTypeProperty
			unique (Level0Type, Level1Type, Level2Type, PropertyName),
		
		constraint CK_EntityPropertyRules_UsageEnumeration
			check (Usage in ('optional', 'required', 'forbidden'))
	);
	
end;
GO




